#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> missingTwo(vector<int>& nums) {
        int diff = 0,N = nums.size()+2;
        for(auto& x: nums)  diff ^= x;
        while(N){
            diff^=N;
            N--;
        }
        int i = 0;
        for(; i < 32 ; i++){ //找到a.b 两个只出现一次的数字的第一个不同的位
            if((diff>>i )& 1)   break;
        }
        //在利用这个pos位，将1·N和1-N缺失a，b的数组分到两个数组中;
        int a = 0 , b = 0;
        N = nums.size() + 2;
        while(N){
            if((N >> i) &1 )    a ^= N;
            else    b ^= N;
            N--;
        }
        for(auto& x: nums){
            if((x >> i) &1 )    a ^= x;
            else    b ^= x;
        }
        return {a,b};
    }
};

int main(){
    vector<int> v{1};
    Solution().missingTwo(v);
    return 0;
}